home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr31 / hades.zip / GECOS.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  6KB  |  225 lines

  1.  
  2. /***************
  3. **
  4. **  gecos.c
  5. **  last revised: april 10, 1992
  6. **
  7. **  Gecos version 1.00 alpha, Copyright (C)1992 Zabkar
  8. **  DESPERATE password-cracker 1.0 alpha using HADES engine by Remote.
  9. **
  10. **  Gecos creates a dictionary from all gecos-fields from the passwordlist
  11. **  on stdin or the file, specified with the -f switch. Output is written on
  12. **  stdout or the file defined with the -o switch.
  13. **
  14. **  Usage: gecos [-c] [-l] [-1] [-r] [-n] [-a] [-f passwordfile] [-o outfile]
  15. **
  16. **  root@waves.hacktic.nl (Zabkar)
  17. **  root@room101.hacktic.nl (Remote)
  18. **
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include "dictword.h"
  24. #include "pwd.h"
  25.  
  26.  
  27. FILE *outfile;
  28. FILE *infile;
  29.  
  30. extern FILE *_pw_file;
  31.  
  32.  
  33. /***************
  34.  haltusage()
  35.  prints correct usage and exits
  36. ****************/
  37.  
  38. void haltusage()
  39. {
  40.   fprintf(stderr,
  41.   "Gecoslist version 1.00 alpha, Copyright (C)1992 Zabkar\n"\
  42.   "DESPERATE password-cracker 1.0 alpha using HADES engine by Remote.\n\n"\
  43.   "Usage: gecos [-c] [-l] [-1] [-r] [-n] [-f passwordfile] "\
  44.   "[-o outfile]\n\n"\
  45.   "\t-c: capitalize whole word\n"\
  46.   "\t-l: lowercase whole word\n"\
  47.   "\t-1: all lowercase, first uppercase\n"\
  48.   "\t-r: all selected options reversed, too\n"\
  49.   "\t-a: allways write all gecos-words, do not check syntax\n"\
  50.   "\t-f: read from 'passwordfile' instead of stdin\n"\
  51.   "\t-o: write to 'outfile' instead of stdout\n\n"\
  52.   "Use of one of the options c, l or 1 causes the normal word to disapear,\n"\
  53.   "to have the normal form back again, add the -n switch.\n\n"\
  54.   "no -f specified: passwordfile read from stdin\n"\
  55.   "no -o specified: output written to stdout\n");
  56.   exit(0);
  57. }
  58.  
  59.  
  60.  
  61. /***************
  62.  creategecoslist()
  63.  creates a userlist from input given on file inf and writes output to
  64.  file of. All conversions of mode are taken care of.
  65. ****************/
  66.  
  67. void creategecoslist(FILE *inf, FILE *of, int mode)
  68. {
  69.     struct passwd *buf;
  70.     char buffer[256];
  71.     char dest[256];
  72.     char words[15][80];
  73.     int i,j,k;
  74.  
  75.     _pw_file = inf;
  76.  
  77.     while ((buf=getpwent()) != NULL)
  78.     {
  79.        /* make words */
  80.        j=0;
  81.        k=0;
  82.        for (i=0; i<strlen(buf->pw_gecos); i++)
  83.        {
  84.           if ((isspace(buf->pw_gecos[i])) || (ispunct(buf->pw_gecos[i])))
  85.           {
  86.             if (k>2)
  87.               {
  88.               words[j][k] = '\0';
  89.               j++;       /* next word */
  90.               k=0;
  91.               }
  92.             else
  93.               k=0;
  94.  
  95.           }
  96.           else if ((mode & CHECK) && !isalpha(buf->pw_gecos[i]))
  97.             { k=0; }
  98.           else
  99.             words[j][k++] = buf->pw_gecos[i];
  100.        }
  101.        if (k>0)
  102.             words[j++][k] = '\0';
  103.  
  104.        for (i=0; i<j; i++)
  105.        {
  106.          strcpy(buffer, "");
  107.          if (mode & NORMAL || mode & EXTNORMAL)
  108.          {
  109.             strcat(buffer, words[i]);
  110.             strcat(buffer, "\n");
  111.          }
  112.  
  113.          if (mode & LOWER)
  114.          {
  115.             strcat(buffer, all_lower(dest, words[i]));
  116.             strcat(buffer, "\n");
  117.          }
  118.  
  119.          if (mode & UPPER)
  120.          {
  121.             strcat(buffer, all_upper(dest, words[i]));
  122.             strcat(buffer, "\n");
  123.          }
  124.  
  125.          if (mode & FIRSTUP)
  126.          {
  127.             strcat(buffer, first_upper(dest, words[i]));
  128.             strcat(buffer, "\n");
  129.          }
  130.  
  131.          if (mode & REVERSE)
  132.          {
  133.             reverse(dest, buffer);    /* reverse of all the above */
  134.             strcat(buffer, &dest[1]); /* strip leading newline */
  135.             strcat(buffer, "\n");     /* add line-feed to end */
  136.          }
  137.  
  138.          fprintf(of, "%s", buffer);   /* Print all words on of */
  139.        }
  140.     }
  141. }
  142.  
  143.  
  144.  
  145. /***************
  146.  main()
  147.  main function of gecos
  148. ****************/
  149.  
  150. main(char argc, char **argv)
  151. {
  152.   char fname[80], oname[80];
  153.   int i;
  154.   int convmode = NORMAL | CHECK;
  155.  
  156.   strcpy(fname, "");
  157.   strcpy(oname, "");
  158.  
  159.   if (argc > 1)
  160.   {
  161.     for (i=1; i<argc; i++)
  162.     {
  163.       switch(argv[i][0])
  164.       {
  165.       case '-': switch(toupper(argv[i][1]))
  166.           {
  167.             case 'F' : if (strlen(argv[i]) > 2)
  168.                  strcpy(fname, &argv[i][2]);
  169.                    else if (argc < (i+2))
  170.                  haltusage();
  171.                    else
  172.                  strcpy(fname, argv[++i]);
  173.                    break;
  174.             case 'O' : if (strlen(argv[i]) > 2)
  175.                  strcpy(oname, &argv[i][2]);
  176.                    else if (argc < (i+2))
  177.                  haltusage();
  178.                    else
  179.                  strcpy(oname, argv[++i]);
  180.                    break;
  181.             case 'C': convmode |= UPPER; convmode &= ~NORMAL; break;
  182.             case 'L': convmode |= LOWER; convmode &= ~NORMAL; break;
  183.             case '1': convmode |= FIRSTUP; convmode &= ~NORMAL; break;
  184.             case 'R': convmode |= REVERSE; break;
  185.             case 'N': convmode |= EXTNORMAL; break;
  186.             case 'A': convmode &= ~CHECK; break;
  187.             default  : haltusage();
  188.           }
  189.           break;
  190.       default : haltusage();
  191.       }
  192.     }
  193.   }
  194.  
  195.   if (strcmp(fname,""))
  196.     infile = fopen(fname, "rt");
  197.   else
  198.     infile = stdin;
  199.  
  200.   if (!infile)
  201.     {
  202.     fprintf(stderr, "gecos: %s: couldn't open file\n", fname);
  203.     exit(0);
  204.     }
  205.  
  206.   if (strcmp(oname, ""))
  207.     outfile = fopen(oname, "wt");
  208.   else
  209.     outfile = stdout;
  210.  
  211.   if (!outfile)
  212.     {
  213.     fprintf(stderr, "gecos: %s: could't create file\n", oname);
  214.     exit(0);
  215.     }
  216.  
  217.   creategecoslist(infile, outfile, convmode);
  218.  
  219.   fclose(infile);
  220.   fclose(outfile);
  221.  
  222.   }
  223.  
  224. /* EOF GECOS.C */
  225.